package com.huizu.goods.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.huizu.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.huizu.goods.domain.ShopImage;
import com.huizu.goods.mapper.ShopNewsMapper;
import com.huizu.goods.domain.ShopNews;
import com.huizu.goods.service.IShopNewsService;
import com.huizu.common.core.text.Convert;

/**
 * 店铺信息Service业务层处理
 * 
 * meidouhui
 * @date 2021-12-06
 */
@Service
public class ShopNewsServiceImpl implements IShopNewsService 
{
    @Autowired
    private ShopNewsMapper shopNewsMapper;
    
   

    /**
     * 查询店铺信息
     * 
     * @param id 店铺信息主键
     * @return 店铺信息
     */
    @Override
    public ShopNews selectShopNewsById(Long id)
    {
        return shopNewsMapper.selectShopNewsById(id);
    }

    /**
     * 查询店铺信息列表
     * 
     * @param shopNews 店铺信息
     * @return 店铺信息
     */
    @Override
    public List<ShopNews> selectShopNewsList(ShopNews shopNews)
    {
        return shopNewsMapper.selectShopNewsList(shopNews);
    }

    /**
     * 新增店铺信息
     * 
     * @param shopNews 店铺信息
     * @return 结果
     */
    @Transactional
    @Override
    public int insertShopNews(ShopNews shopNews)
    {
        int rows = shopNewsMapper.insertShopNews(shopNews);
        insertShopImage(shopNews);
        return rows;
    }

    /**
     * 修改店铺信息
     * 
     * @param shopNews 店铺信息
     * @return 结果
     */
    @Transactional
    @Override
    public int updateShopNews(ShopNews shopNews)
    {
        return shopNewsMapper.updateShopNews(shopNews);
    }

    /**
     * 批量删除店铺信息
     * 
     * @param ids 需要删除的店铺信息主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteShopNewsByIds(String ids)
    {
        return shopNewsMapper.deleteShopNewsByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除店铺信息信息
     * 
     * @param id 店铺信息主键
     * @return 结果
     */
    @Override
    public int deleteShopNewsById(Long id)
    {
        return shopNewsMapper.deleteShopNewsById(id);
    }

    /**
     * 新增店铺照片及营业执照信息
     * 
     * @param shopNews 店铺信息对象
     */
    public void insertShopImage(ShopNews shopNews)
    {
        List<ShopImage> shopImageList = shopNews.getShopImageList();
        Long id = shopNews.getId();
        if (StringUtils.isNotNull(shopImageList))
        {
            List<ShopImage> list = new ArrayList<ShopImage>();
            for (ShopImage shopImage : shopImageList)
            {
                shopImage.setShopId(id);
                list.add(shopImage);
            }
            if (list.size() > 0)
            {
                shopNewsMapper.batchShopImage(list);
            }
        }
    }
}
